package com.tsyz.servlet.config;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * http://localhost:8080/swagger-ui/index.html  访问swagger
 *
 * @author ext.zhaoke14
 */
@Configuration
public class TsyzSwaggerConfig {

    @Value("${swagger.enabled:false}")
    private boolean swaggerEnabled;

    @Value("${spring.profiles.active:}")
    private String activeProfile;

    @Bean
    public OpenAPI customOpenApi() {
        // 生产环境默认关闭Swagger
        if (activeProfile.contains("prod") && !swaggerEnabled) {
            return null;
        }

        if (!swaggerEnabled) {
            return null;
        }

        return new OpenAPI()
                .info(new Info()
                        .title("用户管理系统API文档")
                        .version("1.0")
                        .description("用户管理系统接口文档")
                        .contact(new Contact()
                                .name("联系人名字:天时雨泽")
                        )
                        .license(new License()
                                .name("Apache 2.0")
                                .url("https://www.apache.org/licenses/LICENSE-2.0")));
    }
}
